from  import font_manager, pyplot as plt

my_font = font_manager.FontProperties(fname="/System/Library/Fonts/PingFang.ttc")

y_1 = [1, 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1]
y_2 = [1, 5, 1, 1, 2, 4, 4, 2, 3, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1]
x = range(11, 31)

# 设置图形大小
plt.figure(figsize=(20, 8), dpi=80)
plt.plot(x, y_1, label="自己", color="#F08080")
plt.plot(x, y_2, label="同桌", color="#DB7093", linestyle="--")

x_step = ['{}岁'.format(i) for i in x]
y_step = ['{}个'.format(i) for i in range(9)]
plt.xticks(x, x_step, fontproperties=my_font)
plt.yticks(range(9))
plt.xlabel("年龄", fontproperties=my_font)
plt.ylabel("每年交往女朋友数量", fontproperties=my_font)
plt.grid()
# 添加图例
plt.legend(prop=my_font, loc="upper left")
plt.show()
